/**
 * Created by hps on 17-4-27.
 */
public class ClassDataArray {
    private Person[] a;
    private int nElems;

    public ClassDataArray(int max) {
        a = new Person[max];
        nElems = 0;
    }

    public Person find(String searchName) {
        int i;
        for(i = 0; i < nElems; i++)
            if(a[i].getLastName().equals(searchName))
                break;
        if(i == nElems)
            return null;
        return a[i];
    }

    public void insert(Person person) {
        a[nElems++] = person;
    }

    public boolean delete(String searchName) {
        int i;
        for(i = 0; i < nElems; i++)
            if(a[i].getLastName().equals(searchName))
                break;
        if(i == nElems)
            return false;
        for(int k = i; k < nElems - 1; k++)
            a[k] = a[k + 1];
        nElems--;
        return true;
    }

    public void displayAll() {
        for (int i = 0; i < nElems; i++) {
            a[i].displayPerson();
        }
    }
}
